package com.zwface.demo.function.attendance;

import android.graphics.Color;

import com.blankj.utilcode.util.ColorUtils;
import com.zwface.demo.R;
import com.zwface.demo.base.BaseActivity;
import com.zwface.demo.databinding.ActivityAttendanceOverviewBinding;
import com.zwface.demo.greendao.AttendanceManager;
import com.zwface.demo.greendao.LeaveManager;
import com.zwface.demo.greendao.UserInfoManager;
import com.zwface.demo.model.db.Attendance;
import com.zwface.demo.model.db.Leave;
import com.zwface.demo.model.db.UserInfo;
import com.zwface.demo.view.PieChartView;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * created by      张中文
 * on:             2020/4/29 9:00
 * 描述：
 */
public class AttendanceOverviewActivity extends BaseActivity<ActivityAttendanceOverviewBinding>
{
    @Override
    public int onLayoutId() {
        return R.layout.activity_attendance_overview;
    }

    @Override
    public void onInitComponent() {
        super.onInitComponent();
        initTopbar();
        setPie();
    }

    private void initTopbar(){
        binding.topbar.setTitle("考勤概览");
        binding.topbar.addLeftBackImageButton().setOnClickListener(view -> finish());
    }

    private void setPie(){
        List<PieChartView.PieceDataHolder> pieceDataHolders = new ArrayList<>();

        int Total = 0,AttendanceNum = 0,LeaveNum = 0,notAttendanceNum = 0;
        //所有注册的学生
        List<UserInfo> allStus = UserInfoManager.queryAllStus();
        if(allStus != null)
            Total = allStus.size();
        //所有今天签到的学生
        Map<String,Attendance> todayAtt = AttendanceManager.queryAttendancesToday();
        if(todayAtt != null)
            AttendanceNum = todayAtt.size();
        //所有今天请假的学生
        Map<Long, Leave> todayLeave = LeaveManager.queryLeavesToday();
        if(todayLeave != null)
            LeaveNum = todayLeave.size();

        notAttendanceNum = Total - AttendanceNum - LeaveNum;

        binding.tvInfo.setText("今天已签到"+AttendanceNum+"名学生，"+LeaveNum+"人请假，"+notAttendanceNum
                +"人未签到，共注册"+Total+"名学生");

        pieceDataHolders.add(new PieChartView.PieceDataHolder(notAttendanceNum,Color.GRAY, "未签到-"+notAttendanceNum));
        pieceDataHolders.add(new PieChartView.PieceDataHolder(AttendanceNum, ColorUtils.getColor(R.color.theme), "签到-"+AttendanceNum));
        pieceDataHolders.add(new PieChartView.PieceDataHolder(LeaveNum, Color.RED, "请假-"+LeaveNum));

        binding.pieChart.setData(pieceDataHolders);
    }
}
